// pages/publish/manageProgress.js
const httpUtils = require('../../utils/httpUtils')
const ui = require('../../utils/ui')
const systemInfo = wx.getWindowInfo();
const bottomInset = Math.abs(systemInfo.safeArea.bottom - systemInfo.windowHeight);

//按钮颜色
var button_color = "#FF4B55";
//按钮是否可以点击
var button_enable = true;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    task_no: '',
    task_title: '任务标题',
    task_surplus: '0/0',
    task_price: '￥0',
    task_amount: '￥0',
    button_status: '任务详情',
    task_status: '',
    steps: []
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.setData({
      scrollViewBottomInset: bottomInset + 64,
      bottomInset: bottomInset,
      task_no: options.taskNo,
      button_enable: button_enable
    });
    this.requestProgress();
  },
  //请求进程数据
  requestProgress() {
    let obj = {
      method: 'GET',
      url: '/task/published/' + this.data.task_no + '/process-result',
      data: {}
    }
    httpUtils.request(obj).then(res => {
      if (res.data.taskStatus == '审核失败') {
        this.setData({
          button_status: '修改任务'
        })
      } else if (res.data.taskStatus == '待付款') {
        this.setData({
          button_status: '去支付'
        })
      } else if (res.data.taskStatus == '进行中' || res.data.taskStatus == '等待结束' || res.data.taskStatus == '已结束') {
        this.setData({
          button_status: '查看提交结果'
        })
      }
      this.setData({
        task_no: res.data.taskNo,
        task_title: res.data.taskTitle,
        task_time: res.data.bidSubmitDurationTimeDisplay,
        task_surplus: res.data.leftBidTimeDisplay,
        task_price: res.data.rewardAmountDisplay,
        task_amount: res.data.taskAllRewardAmountDisplay,
        steps: res.data.historySteps,
        task_status: res.data.taskStatus
      })
    }).catch(err => {
      console.log(err)
    });
  },
    //任务详情
    actionTaskDetail() {
      wx.navigateTo({
        url: '/pages/task/taskDetail?taskNo='+this.data.task_no,
      })
    },
    //点击任务
    actionTask() {
      if (this.data.button_status == '修改任务') {
        ui.showToast('未开放');
      } else if (this.data.button_status == '去支付') {
        ui.showToast('未开放');
      } else if (this.data.button_status == '查看提交结果') {
        wx.navigateTo({
          url: '/pages/publish/examineTask?taskNo='+this.data.task_no,
        })
      } else {
        wx.navigateTo({
          url: '/pages/task/taskDetail?taskNo='+this.data.task_no,
        })
      }
    }
})